Skip to content

Conversation

@lordmilko
Copy link

@lordmilko lordmilko commented Jan 16, 2026

#147

While attempting to convert a Java file, JavaToCSharp crashed while parsing the following method parameter

Structure struct

struct is a keyword in C#, but not in Java. As such, JavaToCSharp.Declarations.MethodDeclarationVisitor.VisitInternal was crashing here

var paramSyntax = SyntaxFactory.Parameter(
    attributeLists: [],
    modifiers: modifiers,
    type: TypeHelper.ConvertTypeSyntax(type, arrayLevel),
    identifier: SyntaxFactory.ParseToken(identifier),
    @default: null);

on the basis that the value passed to the identifier parameter was invalid. SyntaxFactory.ParseToken will produce a token of type SyntaxKind.StructKeyword in response to parsing struct rather than a simple identifier token. Earlier in VisitInternal the method TypeHelper.EscapeIdentifier is called, which prepends @ to several types of keywords. Not all keywords are listed here however, so I have updated the list to specify all standard keywords as defined here. There are additional contextual keywords in C# but these should not apply for the purposes of escaping an identifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant